/**
 * Copyright (C), 2024, xxxx有限公司
 * FileName: WeatherService
 * Author:   TLVM
 * Date:     4/21/2024 6:19 PM
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.iqcctt.orangelightaiassistant.call;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.extern.slf4j.Slf4j;
import java.util.function.Function;


/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author TLVM
 * @create 4/21/2024
 * @since 1.0.0
 */
@Slf4j
public class WeatherService implements Function<WeatherService.Request, WeatherService.Response> {

    /**
     * Weather Function request.
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonClassDescription("查询城市天气API接口")
    public record Request(@JsonProperty(required = true,
            value = "location") @JsonPropertyDescription("城市或市或区县 例如：贵州、贵州贵阳、贵阳观山湖") String location) {
    }


    /**
     * Weather Function response.
     */
    public record Response(String weather) {
    }

    public WeatherService.Response apply(WeatherService.Request request) {
        log.info("location: {}", request.location);
        log.debug("调用天气方法，根据AI返回参数进行回调、AI回答参数：{}",request);
        String weather = "";
        if (request.location().contains("广州")) {
            weather = "小雨转阴 13~19°C";
        } else if (request.location().contains("深圳")) {
            weather = "阴 15~26°C";
        } else {
            weather = "热到中暑 99~100°C";
        }

        return new WeatherService.Response(weather);
    }
}
